package cn.kgc.shiro;

import org.apache.shiro.authc.*;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;

/**
 * @author 课工场
 * @date 2023/11/20
 * @description
 */
public class CustomerRealm   extends AuthorizingRealm {


    // 授权方法
    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
        return null;
    }


    //  认证方法
    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
        System.out.println("--------------doGetAuthenticationInfo----------------------");
        UsernamePasswordToken  usernamePasswordToken = (UsernamePasswordToken) token;
        String username = usernamePasswordToken.getUsername();
        System.out.println("username = " + username);
        // char[] password = usernamePasswordToken.getPassword();
        // System.out.println("password = " +  new String(password));
        //  TODO   根据用户名查询数据库
        if ("jack".equals(username)){
            //  TODO   将从数据库中查询的用户信息 封装成SimpleAuthenticationInfo
            SimpleAuthenticationInfo simpleAuthenticationInfo
                    = new SimpleAuthenticationInfo("jack","666666","CustomerRealm");
            return simpleAuthenticationInfo;
        }

        return  null;
    }
}
